home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / SEM.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  4KB  |  115 lines

  1. #ifndef _LINUX_SEM_H
  2. #define _LINUX_SEM_H
  3.  
  4. #include <linux/ipc.h>
  5.  
  6. /* semop flags */
  7. #define SEM_UNDO        0x1000  /* undo the operation on exit */
  8.  
  9. /* semctl Command Definitions. */
  10. #define GETPID  11       /* get sempid */
  11. #define GETVAL  12       /* get semval */
  12. #define GETALL  13       /* get all semval's */
  13. #define GETNCNT 14       /* get semncnt */
  14. #define GETZCNT 15       /* get semzcnt */
  15. #define SETVAL  16       /* set semval */
  16. #define SETALL  17       /* set all semval's */
  17.  
  18. /* ipcs ctl cmds */
  19. #define SEM_STAT 18
  20. #define SEM_INFO 19
  21.  
  22. /* One semid data structure for each set of semaphores in the system. */
  23. struct semid_ds {
  24.     struct ipc_perm    sem_perm;        /* permissions .. see ipc.h */
  25.     __kernel_time_t    sem_otime;        /* last semop time */
  26.     __kernel_time_t    sem_ctime;        /* last change time */
  27.     struct sem    *sem_base;        /* ptr to first semaphore in array */
  28.     struct sem_queue *sem_pending;        /* pending operations to be processed */
  29.     struct sem_queue **sem_pending_last;    /* last pending operation */
  30.     struct sem_undo    *undo;            /* undo requests on this array */
  31.     unsigned short    sem_nsems;        /* no. of semaphores in array */
  32. };
  33.  
  34. /* semop system calls takes an array of these. */
  35. struct sembuf {
  36.     unsigned short  sem_num;    /* semaphore index in array */
  37.     short        sem_op;        /* semaphore operation */
  38.     short        sem_flg;    /* operation flags */
  39. };
  40.  
  41. /* arg for semctl system calls. */
  42. union semun {
  43.     int val;            /* value for SETVAL */
  44.     struct semid_ds *buf;        /* buffer for IPC_STAT & IPC_SET */
  45.     unsigned short *array;        /* array for GETALL & SETALL */
  46.     struct seminfo *__buf;        /* buffer for IPC_INFO */
  47.     void *__pad;
  48. };
  49.  
  50. struct  seminfo {
  51.     int semmap;
  52.     int semmni;
  53.     int semmns;
  54.     int semmnu;
  55.     int semmsl;
  56.     int semopm;
  57.     int semume;
  58.     int semusz;
  59.     int semvmx;
  60.     int semaem;
  61. };
  62.  
  63. #define SEMMNI  128             /* ?  max # of semaphore identifiers */
  64. #define SEMMSL  32              /* <= 512 max num of semaphores per id */
  65. #define SEMMNS  (SEMMNI*SEMMSL) /* ? max # of semaphores in system */
  66. #define SEMOPM  32            /* ~ 100 max num of ops per semop call */
  67. #define SEMVMX  32767           /* semaphore maximum value */
  68.  
  69. /* unused */
  70. #define SEMUME  SEMOPM          /* max num of undo entries per process */
  71. #define SEMMNU  SEMMNS          /* num of undo structures system wide */
  72. #define SEMAEM  (SEMVMX >> 1)   /* adjust on exit max value */
  73. #define SEMMAP  SEMMNS          /* # of entries in semaphore map */
  74. #define SEMUSZ  20        /* sizeof struct sem_undo */
  75.  
  76. #ifdef __KERNEL__
  77.  
  78. /* One semaphore structure for each semaphore in the system. */
  79. struct sem {
  80.     int    semval;        /* current value */
  81.     int    sempid;        /* pid of last operation */
  82. };
  83.  
  84. /* One queue for each semaphore set in the system. */
  85. struct sem_queue {
  86.     struct sem_queue *    next;     /* next entry in the queue */
  87.     struct sem_queue **    prev;     /* previous entry in the queue, *(q->prev) == q */
  88.     struct wait_queue *    sleeper; /* sleeping process */
  89.     struct sem_undo *    undo;     /* undo structure */
  90.     int                pid;     /* process id of requesting process */
  91.     int                status;     /* completion status of operation */
  92.     struct semid_ds *    sma;     /* semaphore array for operations */
  93.     struct sembuf *        sops;     /* array of pending operations */
  94.     int            nsops;     /* number of operations */
  95.     int            alter;     /* operation will alter semaphore */
  96. };
  97.  
  98. /* Each task has a list of undo requests. They are executed automatically
  99.  * when the process exits.
  100.  */
  101. struct sem_undo {
  102.     struct sem_undo *    proc_next;    /* next entry on this process */
  103.     struct sem_undo *    id_next;    /* next entry on this semaphore set */
  104.     int            semid;        /* semaphore set identifier */
  105.     short *            semadj;        /* array of adjustments, one per semaphore */
  106. };
  107.  
  108. asmlinkage int sys_semget (key_t key, int nsems, int semflg);
  109. asmlinkage int sys_semop (int semid, struct sembuf *sops, unsigned nsops);
  110. asmlinkage int sys_semctl (int semid, int semnum, int cmd, union semun arg);
  111.  
  112. #endif /* __KERNEL__ */
  113.  
  114. #endif /* _LINUX_SEM_H */
  115.